from sqlalchemy.engine import create_engine
from sqlalchemy.schema import MetaData, Table, Column, ForeignKey, Sequence
from sqlalchemy.types import *

engine = create_engine('sqlite:////1.db', echo=True)
#engine = create_engine('postgres://test:test@localhost/test', echo=True)

metadata = MetaData()
metadata.bind = engine

book_table = Table('book', metadata,
    Column('id', Integer, Sequence('seq_pk'), primary_key=True),
    Column('title', Unicode(255), nullable=False),
)

author_table = Table('author', metadata,
    Column('id', Integer, Sequence('seq_pk'), primary_key=True),
    Column('name', Unicode(255), nullable=False),
)

bookauthor_table = Table('bookauthor', metadata,
   Column('book_id', Integer, ForeignKey('book.id'), nullable=False),
   Column('author_id', Integer, ForeignKey('author.id'), nullable=False),
)

metadata.create_all(checkfirst=True)
